package ca.uwo.android.library;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.AdapterView.OnItemClickListener;
import ca.uwo.android.HomeScreenActivity;
import ca.uwo.android.R;
import ca.uwo.android.alumni.AlumniBranches;
import ca.uwo.android.alumni.AlumniHomecoming;
import ca.uwo.android.giveback.GiveBack;
import ca.uwo.android.rss.events.RssDatesFeed;

public class LibraryMain extends HomeScreenActivity {

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		GridView gridView = (GridView) findViewById(getGridViewId());
		gridView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View v,
					int position, long id) {
				if (position == 0)
					startActivityFromChild(LibraryMain.this, new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.library_databases_href))), -1);
				else if (position == 1)
					startActivityFromChild(LibraryMain.this, new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.library_hours_href))), -1);
				else if (position == 2)
					startActivityFromChild(LibraryMain.this, new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.library_contacts_href))), -1);
				else if (position == 3)
					startActivityFromChild(LibraryMain.this, new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.library_news_href))), -1);
				else if (position == 4)
					startActivityFromChild(LibraryMain.this, new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.library_catalogue_href))), -1);
				else if (position == 5)
					startActivityFromChild(LibraryMain.this, new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.library_fullsite_href))), -1);
				else
					alert("Not yet implemented.", false);

			}

		});

	}
	
	/**
	 * This method is called when the "Library Account" button is
	 * clicked. It redirects opens up the library login page
	 * 
	 * @param v
	 *            the button view that is clicked
	 */
	public void libraryLoginButtonClick(View v) {

		// show url in browser
		Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.library_account_href)));
		startActivity(browser); // show url in browser
	}

	@Override
	protected Integer[] getModuleIcons() {
		Integer[] icons = { R.drawable.library_databases,
				R.drawable.library_hours, R.drawable.directory_search,
				R.drawable.western_news, R.drawable.library_catalogue,
				R.drawable.library_fullsite

		};
		return icons;
	}

	@Override
	protected int getContentViewId() {
		return R.layout.library_main;
	}

	@Override
	protected int getGridViewId() {
		return R.id.libraryGridView;
	}

	@Override
	protected int getModuleNames() {
		return R.array.library_module_name_array;
	}

}
